
import pandas as pd

def read_csv():
    df = pd.read_csv('508延秒数据源.csv')
    #print(df['投放url'].str.extract(r'((?<=brandid=)\d+)', expand=False))
    df['广告id']=df['投放url'].str.extract(r'((?<=brandid=)\d+)', expand=False)
    #print(df['广告id'])
    ribao_df=pd.read_csv('日报数据.csv')
    ribao_df['广告id'] = ribao_df['链接'].str.extract(r'((?<=brandid=)\d+)', expand=False)
    df_result = pd.merge(df, ribao_df[['广告id', '广告主pin', '延秒上线日期', '品牌', '优化师']], how='inner', on=['广告id','广告主pin'])
    # print(df_result)
    # writer = pd.ExcelWriter('output.xlsx')
    # df_result.loc[0:5000, :] .to_excel(writer, '匹配结果')
    # writer.save()
    df_result.to_csv('output.csv', encoding='utf_8_sig')

read_csv()

